package com.hqd.ch03.v49.io.support;

import com.hqd.ch03.utils.ResourceUtils;
import com.hqd.ch03.v49.io.ResourceLoader;

public abstract class ResourcePatternUtils {

    public static boolean isUrl(String resourceLocation) {
        return (resourceLocation != null &&
                (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX) ||
                        ResourceUtils.isUrl(resourceLocation)));
    }

    public static ResourcePatternResolver getResourcePatternResolver(ResourceLoader resourceLoader) {
        if (resourceLoader instanceof ResourcePatternResolver) {
            return (ResourcePatternResolver) resourceLoader;
        } else if (resourceLoader != null) {
            return new PathMatchingResourcePatternResolver(resourceLoader);
        } else {
            return new PathMatchingResourcePatternResolver();
        }
    }

}

